package com.lindroid.androiduilearning.textview.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import com.lindroid.androiduilearning.R;
import com.lindroid.androiduilearning.base.BaseFragment;
import com.lindroid.androiduilearning.util.UIUtil;

/**
 * @author Lin
 * @date 2018/3/9
 * @function
 */

public class AutoSizeFragment extends BaseFragment {

    private EditText etInput;
    private TextView tvContent;
    private TextView tvSize;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_auto_size, null, false);
        initView(view);
        return view;
    }


    private void initView(View view) {
        etInput = view.findViewById(R.id.et_input);
        tvContent = view.findViewById(R.id.tv_content);
        tvSize = view.findViewById(R.id.tv_size);

        etInput.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                tvContent.setText(s);
                tvSize.setText(new StringBuffer("TextSize:").append(UIUtil.px2sp(context, tvContent.getTextSize())).append("sp"));
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }
}
